package com.example.fresheveryday.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fresheveryday.po.Log;
import com.example.fresheveryday.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    LogService logService;
    @RequestMapping("/getLogList")
    public IPage<Log> getLog(@RequestBody Map map){
        Page<Log> page = new Page<>();
        page.setCurrent(Integer.valueOf(map.get("pageNo").toString()))
                .setTotal(logService.count())
                .setSize(Integer.valueOf(map.get("pageSize").toString()));
        return logService.getAllLog(page);
    }
    @RequestMapping("/getLogByUserId")
    public IPage<Log> getById(@RequestBody Map map){
        Page<Log> page = new Page<>();
        String userId = map.get("userId").toString();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id",userId);
        page.setCurrent(Integer.valueOf(map.get("pageNo").toString()))
                .setTotal(logService.countByConditions(wrapper))
                .setSize(Integer.valueOf(map.get("pageSize").toString()));

        return logService.getLogByConditions(page,wrapper);

    }
}
